package net.huashitong.synthetical.newSupervision.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.dao.SysTableDao;
import com.sirdc.modules.sys.service.SysTableService;
import com.sirdc.modules.sys.util.SysUserUtils;
import net.huashitong.synthetical.newSupervision.dao.UnitPersonnelDao;
import net.huashitong.synthetical.newSupervision.entity.UnitPersonnel;
import net.huashitong.synthetical.newSupervision.filter.UnitPersonnelFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/7/15
 * Time: 11:27
 * To change this template use File | Settings | File Templates.
 * Description:
 */

@Service
public class UnitPersonnelService extends StringPKService<UnitPersonnel> {
    @Autowired
    private SysTableService tableService;
    @Autowired
    private UnitPersonnelDao unitPersonnelDao;

    @Override
    protected BaseDao<UnitPersonnel, String> getDao() {
        return this.unitPersonnelDao;
    }

    @Override
    protected void beforeSave(UnitPersonnel obj) {
        obj.setSysId(tableService.updateMaxSysId("t_unit_personnel", null));

    }

    public List<UnitPersonnel> queryFilter(UnitPersonnelFilter filter) {
        return unitPersonnelDao.queryFilter(filter);
    }

    /**
     * 添加
     * @param unitPersonnel
     * @return
     */
    public String createUnitPer(UnitPersonnel unitPersonnel) {
        String deptId = SysUserUtils.getDeptId();
        UnitPersonnelFilter filter = new UnitPersonnelFilter();
        filter.setDeptId(deptId);
        filter.setName(unitPersonnel.getName());
        List<UnitPersonnel>list= unitPersonnelDao.queryFilter(filter);
        if (list.size()>0){
            return "500";
        }
        unitPersonnel.setDeptId(deptId);
        this.save(unitPersonnel);
        return "200";
    }
}
